package cn.jstars.datatocloud.modules.monitor.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cn.jstars.datatocloud.common.entity.Custom;
import cn.jstars.datatocloud.modules.monitor.dao.MonitorMapper;
import cn.jstars.datatocloud.modules.monitor.entity.Toimachinestatus;

@Component
public class MonitorService {

	@Autowired
	private Custom custom;
	@Autowired
	private MonitorMapper monitorMapper;

	public void addColumn(int year, String day) {
		String dataBase = custom.getDbPrefix() + year;
		monitorMapper.addColumn(dataBase, day);
	}

	/**
	 * 查询未级联数据的数量
	 * 
	 * @param year
	 *            年
	 * @param day
	 *            当日
	 * @return 条数
	 */
	public int findCountWithoutUpload(String year, String day) {
		String dataBase = custom.getDbPrefix() + year;
		return monitorMapper.findCountWithoutUpload(dataBase, day);
	}

	/**
	 * 获取未级联数据
	 * 
	 * @param year
	 *            年
	 * @param day
	 *            当日
	 * @return 数据
	 */
	public List<Toimachinestatus> findAllWithoutUpload(String year, String day) {
		String dataBase = custom.getDbPrefix() + year;
		return monitorMapper.findAllWithoutUpload(dataBase, day);
	}

	/**
	 * 批量更新级联状态
	 * 
	 * @param dataList
	 *            数据集合
	 * @return 更新条数
	 */
	public int updateUploadStatus(List<Toimachinestatus> dataList, String year, String day) {
		String dataBase = custom.getDbPrefix() + year;
		return monitorMapper.updateUploadStatus(dataList, dataBase, day);
	}

	/**
	 * 查找没有级联的Equipstatus数据
	 * 
	 * @return 数据集合
	 */
	public List<Toimachinestatus> findEquipstatusWithoutUpload(String year) {
		String dataBase = custom.getDbPrefix() + year;
		return monitorMapper.findEquipstatusWithoutUpload(dataBase);
	}

	/**
	 * 批量更新Equipstatus级联状态
	 * 
	 * @param dataList
	 *            数据集合
	 * @param year
	 *            年份
	 * @return 更新条数
	 */
	public int updateEquipstatusUploadStatus(List<Toimachinestatus> dataList, String year) {
		String dataBase = custom.getDbPrefix() + year;
		return monitorMapper.updateEquipstatusUploadStatus(dataList, dataBase);
	}

	/**
	 * 查询机台参数数据
	 * @param year
	 *            年份
	 * @return 参数数据集合
	 */
	public List<Toimachinestatus> findParamSet(String year){
		String dataBase = custom.getDbPrefix() + year;
		return monitorMapper.findParamSet(dataBase);
	}


	public int updateParamSetUploadStatus(List<Toimachinestatus> list,String year){
		String dataBase = custom.getDbPrefix() + year;
		return monitorMapper.updateParamSetUploadStatus(list,dataBase);
	}

}
